package Database;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import Model.QualityManual;

public class QualityManualDB {
	
	public static void update(String ValURL, String ValManual)
	{
		Connection con = DBConnection.connect(true);
		PreparedStatement stmt = null;
		String select = "UPDATE qualitymanual SET URL = ? WHERE Manual = ?";
		
		try
		{
			stmt = con.prepareStatement(select);
			stmt.setString(1, ValURL);
			stmt.setString(2, ValManual);
			stmt.executeUpdate();
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		finally
		{
			try
			{
				if (stmt != null)
					stmt.close();
				if (con != null)
					con.close();
			}
			catch (SQLException e)
			{
			}
		}
	}
	public static ArrayList <QualityManual> GetManual()
	{
		Connection con = DBConnection.connect(true);
		PreparedStatement stmt = null;
		ResultSet rs = null;
		String select = "SELECT Manual FROM QualityManual ORDER BY Manual";

		ArrayList<QualityManual> manualarry = new ArrayList<QualityManual>();
		QualityManual manual = null;

		try
		{
			stmt = con.prepareStatement(select);
			rs = stmt.executeQuery();
			while (rs.next())
			{
				manual = new QualityManual();
				manual.setManual(rs.getString("Manual"));
				

				manualarry.add(manual);
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
			manual = null;
		}
		finally
		{
			try
			{
				if (rs != null)
					rs.close();
				if (stmt != null)
					stmt.close();
				if (con != null)
					con.close();
			}
			catch (SQLException e)
			{
			}
		}

		return manualarry;
	}
}
